/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Solenoid;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 *
 * @author Paul & Madhav
 */
public class Launcher {
    
    boolean preloaded = false;
    boolean launched = false;
    Joystick xbox;
    DoubleSolenoid mainPiston;
    DoubleSolenoid kickerPiston;
    SmartDashboard smart;
    
    Launcher(int pressureSensor, int compressorRelay, int main1, int main2, int kicker1, int kicker2) {
        Compressor compressor = new Compressor(pressureSensor, compressorRelay);//creates a new compressor
        compressor.start();//maintains air pressure

        xbox = new Joystick(3);//instantiates a new joystick
        mainPiston = new DoubleSolenoid(main1, main2);
        kickerPiston = new DoubleSolenoid(kicker1, kicker2);
        smart = new SmartDashboard();
    }
    
    void run(int preload, int launch, int retract) {
        if (xbox.getRawButton(preload)) {
            preload();
        }
        if (xbox.getRawButton(launch)) {
            launch();
        }
        if (xbox.getRawButton(retract)) {
            retract();
        }
        displayStatus();
    }
    //compresses the main piston

    void preload() {
        mainPiston.set(DoubleSolenoid.Value.kForward);
        preloaded = true;
        
    }
    
    void launch() {
        kickerPiston.set(DoubleSolenoid.Value.kForward);
        launched = true;
    }
    
    void retract() {
        unload();
        kickerPiston.set(DoubleSolenoid.Value.kOff);
        launched = false;
    }

    //retracts the main piston onl
    void unload() {
        mainPiston.set(DoubleSolenoid.Value.kOff);
        preloaded = false;
        
    }
    
    void displayStatus() {
        smart.putBoolean("Launched", launched);
        smart.putBoolean("Preloaded", preloaded);
    }
}
